<?php
/*
 * @Description    : 消息推送数据预处理任务
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2020-01-22 15:56:35
 * @LastEditors    : QianLong
 * @LastEditTime   : 2023-01-31 17:16:21
 */

declare(strict_types=1);

namespace App\Job;

use Hyperf\AsyncQueue\Job;
use App\Common\RedisCache;

class PushDataPreJob extends Job
{
    public $params;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
        if (!empty($this->params) && is_array($this->params)) {
            $redisCache = new RedisCache;
            $cidList = array_flip(array_unique(explode(',',$this->params['cid'])));
            foreach ($cidList as $cid => $in) {
                $this->params['single_cid'] = $cid;
                if (!empty($this->params['filter_id']) && $this->params['is_filter'] == 1) {
                    $result = $redisCache->setFilterCid($this->params['uid'] . ':' . $this->params['filter_id'], $cid);
                    if ($result) {
                        queue_push(new PushSendJob($this->params, $redisCache));
                    }
                } else {
                    queue_push(new PushSendJob($this->params, $redisCache));
                }
            }
            unset($in, $cid, $cidArray2, $result);
        }
    }
}
